objectcache: Improve WANObjectCache test coverage
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 25 Sep 2017 23:21:40 +0000 (00:21 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 28 Sep 2017 17:59:09 +0000 (18:59 +0100)
class WANObjectCache (methods: 40% -> 67%, lines: 65% -> 88%)

* Allow indirect coverage of protected/private utility methods from
  existing tests.
* Add basic test for setLogger().
* Add basic test for newEmpty().
* Add basic test for getQoS().

Change-Id: Ifb79ed2ff1febbd2f5477b8ed6319992ce88eb29

tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php

index 137ef0c..0b2df61 100644 (file)
@@ -2,6 +2,18 @@
 
 use Wikimedia\TestingAccessWrapper;
 
+/**
+ * @covers WANObjectCache::wrap
+ * @covers WANObjectCache::unwrap
+ * @covers WANObjectCache::worthRefreshExpiring
+ * @covers WANObjectCache::worthRefreshPopular
+ * @covers WANObjectCache::isValid
+ * @covers WANObjectCache::getWarmupKeyMisses
+ * @covers WANObjectCache::prefixCacheKeys
+ * @covers WANObjectCache::getProcessCache
+ * @covers WANObjectCache::getNonProcessCachedKeys
+ * @covers WANObjectCache::getRawKeysForWarmup
+ */
 class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
        /** @var WANObjectCache */
        private $cache;
@@ -270,9 +282,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
 
        /**
         * @dataProvider getMultiWithSetCallback_provider
-        * @covers WANObjectCache::getMultiWithSetCallback()
-        * @covers WANObjectCache::makeMultiKeys()
-        * @covers WANObjectCache::getMulti()
+        * @covers WANObjectCache::getMultiWithSetCallback
+        * @covers WANObjectCache::makeMultiKeys
+        * @covers WANObjectCache::getMulti
         * @param array $extOpts
         * @param bool $versioned
         */
@@ -882,7 +894,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
        }
 
        /**
-        * @covers WANObjectCache::delete()
+        * @covers WANObjectCache::delete
+        * @covers WANObjectCache::relayDelete
+        * @covers WANObjectCache::relayPurge
         */
        public function testDelete() {
                $key = wfRandomString();
@@ -988,9 +1002,11 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
        }
 
        /**
-        * @covers WANObjectCache::touchCheckKey()
-        * @covers WANObjectCache::resetCheckKey()
-        * @covers WANObjectCache::getCheckKeyTime()
+        * @covers WANObjectCache::touchCheckKey
+        * @covers WANObjectCache::resetCheckKey
+        * @covers WANObjectCache::getCheckKeyTime
+        * @covers WANObjectCache::makePurgeValue
+        * @covers WANObjectCache::parsePurgeValue
         */
        public function testTouchKeys() {
                $key = wfRandomString();
@@ -1233,6 +1249,40 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
                ];
        }
 
+       /**
+        * @covers WANObjectCache::__construct
+        * @covers WANObjectCache::newEmpty
+        */
+       public function testNewEmpty() {
+               $this->assertInstanceOf(
+                       WANObjectCache::class,
+                       WANObjectCache::newEmpty()
+               );
+       }
+
+       /**
+        * @covers WANObjectCache::setLogger
+        */
+       public function testSetLogger() {
+               $this->assertSame( null, $this->cache->setLogger( new Psr\Log\NullLogger ) );
+       }
+
+       /**
+        * @covers WANObjectCache::getQoS
+        */
+       public function testGetQoS() {
+               $backend = $this->getMockBuilder( HashBagOStuff::class )
+                       ->setMethods( [ 'getQoS' ] )->getMock();
+               $backend->expects( $this->once() )->method( 'getQoS' )
+                       ->willReturn( BagOStuff::QOS_UNKNOWN );
+               $wanCache = new WANObjectCache( [ 'cache' => $backend ] );
+
+               $this->assertSame(
+                       $wanCache::QOS_UNKNOWN,
+                       $wanCache->getQoS( $wanCache::ATTR_EMULATION )
+               );
+       }
+
        /**
         * @covers WANObjectCache::makeKey
         */